package xpn.platform.modules.workflow.other.commentcolumn;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;
import org.springframework.data.rest.core.config.Projection;
import xpn.platform.common.repository.XpnRepository;
import xpn.platform.modules.workflow.definition.state.State;


import java.util.List;

@RepositoryRestResource(path = "workflow_comment_column", excerptProjection = CommentColumnDefaultProjection.class)
public interface CommentColumnDAO extends XpnRepository<CommentColumn, Long> {

    @RestResource(path = "findByProcessId")
    List<CommentColumn> findByProcessIdOrderBySortNoDesc(@Param("id") Long id);

    /**
     * 根据实例ID查询评论栏
     *
     * @param id
     * @return
     */
    @Query(value = "SELECT cc.* FROM " +
            "wf_comment_column cc " +
            "INNER JOIN " +
            "wf_process p " +
            "ON cc.process_id=p.id " +
            "INNER JOIN " +
            "wf_ru_instance i " +
            "ON i.process_id=p.id " +
            "WHERE i.id=?1", nativeQuery = true)
    @RestResource(path = "findByInstanceId")
    List<CommentColumn> findByInstanceId(@Param("id") Long id);
}
/**
 * 缺省投影
 *
 * @author yjx
 */
@Projection(name = "default", types = {State.class})
interface CommentColumnDefaultProjection {

    Long getId();

    String getName();

    Float getSortNo();
    
    String getNo();

}